@Service
public class AlertEngine {
    private final RuleService ruleService;
    
    @KafkaListener(topics = "temperature-data")
    public void handleEvent(TemperatureEvent event) {
        List<AlertRule> rules = ruleService.getActiveRules();
        rules.stream()
            .filter(rule -> rule.match(event))
            .forEach(rule -> triggerAlert(event, rule));
    }
    
    private void triggerAlert(TemperatureEvent event, AlertRule rule) {
        // 分级预警处理
        switch (rule.getLevel()) {
            case LEVEL1 -> sendSms(event.getUser());
            case LEVEL2 -> lockAccount(event.getUser());
            case LEVEL3 -> reportToCDC(event);
        }
    }
}